package com.example.miaoshasoft.services;

import cn.hutool.core.date.DateUtil;
import com.example.miaoshasoft.domain.Student;
import com.example.miaoshasoft.service.StudentsService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class StudentsServices {
    @Resource
    private StudentsService studentsService;
    /**
     * 增
     */
    @Test
    public void testAddStudetns(){
        Student s = new Student();
        s.setName("张楚");
        s.setGender("男");
        s.setBirthday("1998-11-22");
        s.setCreateTime(DateUtil.format(new Date(),"yyyy-MM-dd"));

        studentsService.save(s);
    }
    /**
     * 查
     */
    @Test
    public void testQueryAllStudents(){
        List<Student> students = studentsService.findAll();
        for(Student s : students){
            System.out.println(s);
        }

    }
    @Test
    public void testQueryStudent(){
        Student s = studentsService.getOne(1);
        System.out.println(s);
    }
    /**
     * 改
     */
    @Test
    public void testUpdateStudent(){
        Student s = studentsService.getOne(1);
        s.setGender("女");
        studentsService.save(s);
    }
    /**
     * 删
     */
    @Test
    public void testDeleteStudentBySid(){
        studentsService.deleteById(1);
    }
}
